﻿/*----------------------------------------------------------------
//文件名：LoginCommon.aspx.cs
//文件功能描述：处理登录。
//创建人：赵国伟
//创建时间：2012-03-17 16:34:54
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Shopping.Common;
using Shopping.BLL;
using Shopping.Model;

public partial class Manage_AS_LoginCommon : System.Web.UI.Page
{
    private readonly EmployeesManage bllEmployees = new EmployeesManage();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string action = Request.QueryString["Action"] + "";
            switch (action)
            {
                case "Login":  //用户登录；//by 赵国伟 2012-03-17
                    Login();
                    break;
            }

        }
        Response.End();
    }

    #region "员工登录 by 赵国伟 2012-03-17"
    /// <summary>
    /// 员工登录
    /// </summary>
    private void Login()
    {
        string userName = Utility.P("UserName");
        string passWord = Utility.P("PassWord");
        string code = Utility.P("Code");
        ReturnValue ret = new ReturnValue();
        if (string.IsNullOrEmpty(userName))
        {
            ret.Message = "登录账号不能为空！";
            Response.Write(ret.ToJsonString());
            return;
        }
        if (string.IsNullOrEmpty(passWord))
        {
            ret.Message = "登录密码不能为空！";
            Response.Write(ret.ToJsonString());
            return;
        }
        if (string.IsNullOrEmpty(code))
        {
            ret.Message = "验证码不能为空！";
            Response.Write(ret.ToJsonString());
            return;
        }

        if (code.ToLower() != Utility.GetCookies("CheckCode").ToLower())
        {
            ret.Message = "验证码输入错误！";
            Response.Write(ret.ToJsonString());
            return;
        }

        Employees employee = bllEmployees.GetUserInfoByName(userName);
        if (employee == null)
        {
            ret.Message = "用户名错误！";
            Response.Write(ret.ToJsonString());
            return;
        }
        string m = Utility.MD5(passWord);
        if (employee.PassWord != Utility.MD5(passWord))
        {
            ret.Message = "登录密码错误！";
            Response.Write(ret.ToJsonString());
            return;
        }


        if (employee.Status != Status.正用.ToString())
        {
            ret.Message = "您的账号已停用！";
            Response.Write(ret.ToJsonString());
            return;
        }

        //验证成功；写入登录信息；
        bllEmployees.Login(employee);
        ret.Result = ResultType.Success;
        Response.Write(ret.ToJsonString());

    }
    #endregion


}